package com.chen.wow.day04.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.chen.wow.day04.mvc.domain.User;

@Controller
public class HelloController {
	@RequestMapping(value = "/")
	public String home(){
		System.out.println("home begin");
		return "homes";
	}
	
	/**
	 * 
	 * @Description: 查询参数
	 * @param @param name
	 * @param @return   
	 * @return String  
	 * @throws
	 * @author cyb
	 * @date 2017-4-25
	 */
	@RequestMapping(value = "query")
	public String queryParameter(String name){
		System.out.println("name = " + name);
		return "query";
	}
	
	@RequestMapping(value = "/redirect")
	public String redirect(){
		return "redirect:/file/index";
	}
	
	@RequestMapping(value = "/redirectUrl")
	public String redirectUrl(Model model){
		model.addAttribute("title", "123");
		return "redirect:/file/show/{title}";
	}
	
	@RequestMapping(value = "/redirectFlash")
	public String redirectFlash(RedirectAttributes model){
		User user = new User();
		user.setId(1);
		user.setName("测试");
		
		//flash属性会一直携带这些数据直到下一次请求，然后才会消失
		model.addFlashAttribute("user", user);
		
		return "redirect:/file/flash";
	}
}
